<template>
    <div>
        <div style="margin: 50px auto; width: 80%; text-align: center">
            <input type="text" v-model="search"> <button @click="onSearch">搜索</button>
        </div>
        <div v-for="(news, index) in news_list" :key="index" style="margin: 20px auto; width: 80%; text-align: center; font-size: 20px">
            <a :href="news._source.href">{{news._source.title}}</a>
        </div>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            search: '',
            news_list: []
        }
    },
    methods: {
        onSearch() {
            // 实例化
            let form_data = new FormData()
            // 添加数据
            form_data.append('search', this.search)
            // 发送请求
            axios.post('http://127.0.0.1:8000/carthome/search/', form_data).then(res => {
                console.log(res.data)
                this.news_list = res.data.data.hits.hits
                console.log(this.news_list)
            })
        }
    },
    created() {

    }
}
</script>

<style scoped>

</style>
